import 'package:boss/models/printer.dart';
import 'package:boss/ui/widget/button/radius_button.dart';
import 'package:boss/ui/widget/modal/modal.dart';
import 'package:boss/ui/widget/tab_btn.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'printer_list.dart';
import 'printer_provider.dart';

Future showPrinterModal(BuildContext context, {List<int> selectedDeviceId, @required List<Printer> printers}) {
  return showModal(
    context,
    builder: (context) => MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (context) => PrinterProvider(
            defaultSelectedDeviceId: selectedDeviceId,
            printers: printers,
          ),
        ),
      ],
      child: _PrinterModal(),
    ),
  );
}

class _PrinterModal extends StatefulWidget {
  @override
  __PrinterModalState createState() => __PrinterModalState();
}

class __PrinterModalState extends State<_PrinterModal> {

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 620.w,
      height: 660.w,
      padding: EdgeInsets.symmetric(
        vertical: 20.w,
        horizontal: 30.w,
      ),
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
              top: 20.w,
              bottom: 50.w,
            ),
            alignment: Alignment.center,
            child: TabBtn(
              title: '选择打印机',
              isSelected: true,
            ),
          ),
          Expanded(
            child: PrinterList(),
          ),
          Container(
            margin: EdgeInsets.only(
              top: 40.w,
            ),
            child: RadiusButton(
              title: '保 存',
              width: 500.w,
              onTap: () {
                var printerProvider = Provider.of<PrinterProvider>(
                  context,
                  listen: false,
                );

                Navigator.pop(
                  context,
                  printerProvider.selectedPrinters
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
